package business.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.User;
import business.UserService;
import dao.UserDAO;

public class UserServiceImpl implements UserService {

	private UserDAO userDao;

	public List<User> getAllUsers() {
		return userDao.findAll();
	}

	public List<User> getAllUsers(int start,int pageSize) {
		return userDao.findAll(start,pageSize);
	}
	public long getTotalCount() {
		return userDao.findTotalCount();
	}

	
	public User getByUsernamePSW(String username,String psw) {
		return userDao.findByUsernamePSW(username,psw);
	}

	
	@Required
	public void setUserDao(UserDAO userDao) {
		this.userDao = userDao;
	}

	@Transactional
	public void addUser(String name) {
		User e = new User();
		e.setName(name);
		userDao.create(e);
	}

	@Transactional
	public void addUser(User user) {
		userDao.create(user);
	}

	@Transactional
	public User getById(long id) {
		return userDao.getById(id);
	}

	@Transactional
	public User getByName(String name) {
		return userDao.getByName(name);
	}

	@Transactional
	public User getByLoginName(String name) {
		return userDao.getByLoginName(name);
	}

	@Transactional
	public void update(long id) {
		userDao.update(id);
	}

	@Transactional
	public void delete(long id) {
		userDao.delete(id);

	}

}